from typing import Union, List, Optional

from fastapi import APIRouter, Depends, Body, Header, Query, Path, Form
from fastapi.encoders import jsonable_encoder
from odoo.api import Environment
from odoo.addons.fastapi.dependencies import odoo_env
from odoo.addons.fastapi_odoo_bridge.core.response import custom_response
from odoo.addons.fastapi_odoo_bridge.core.basemodel import CommonResponse
from odoo.addons.fastapi_odoo_bridge.core.header import set_lang
from ...basemodels.dto.center_area.center_area import ComplianceAndAgreementsDto
from ...functions.center_area_func import CenterAreaFunc
from ...basemodels.vo.center_area.compliance_and_agreements import ComplianceAndAgreements

"""
Belong:新UI
Description:条款和用户协议部分
"""

router = APIRouter(tags=['条款和协议'])


@router.post(
    path='/get/compliance_and_agreements',
    description='获取条款和用户协议',
    summary='获取条款和用户协议',
    response_model=Union[list, dict, List[dict]]
)
@custom_response
@set_lang
async def get_compliance_and_agreements(compliance_and_agreements: ComplianceAndAgreementsDto = Body(..., description='条款和用户协议'),
                                        env: Environment = Depends(odoo_env), Accept_Language: Optional[str] = Header()):
    func = CenterAreaFunc(env)
    result = func.get_compliance_and_agreements(compliance_and_agreements.type)
    if not isinstance(result, dict):
        result = ComplianceAndAgreements(__from_odoo=result, __env=env)
        result = jsonable_encoder(CommonResponse(code='200', msg='success', data=result))
    return result
